package com.example.sinoyd.frameapplication.ProjectCodes.Fragment

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.example.sinoyd.frameapplication.KotlinFrame.Uitl.showdialogchcek
import com.example.sinoyd.frameapplication.ProjectCodes.About.*
import com.example.sinoyd.frameapplication.ProjectCodes.UI.LoginActivity
import com.example.sinoyd.frameapplication.R
import com.sinoyd.Code.Until.SharedPreferencesFactory
import kotlinx.android.synthetic.main.about_fragment.*
import kotlinx.android.synthetic.main.include_title_layout.*
import org.jetbrains.anko.act
import org.jetbrains.anko.onClick
import org.jetbrains.anko.startActivity

/**
 * 关于界面
 * **/
@SuppressLint("ValidFragment")
class AboutFragment(var name: String = "关于") : BaseFragment() {

    //选择站点后进行的操作
    override fun selectPortCallBack() {
    }


    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        val conview = inflater.inflate(R.layout.about_fragment, null)
        return conview
    }

    override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        setview()
        setlisterens()
    }


    //设置界面
    private fun setview() {
        center_title.text = name
    }

    //设置各种监听
    private fun setlisterens() {
        //检查新版本
        tv_check_version.onClick {
            showdialogchcek(act, "loadshow")
        }
        //空气质量指数等级说明
        tv_level_air.onClick {
            var dialog = LevelExplainDialog(act, R.style.dialog)
            dialog.show()
        }
        //水质等级说明
        tv_level_water.onClick {
            var dialog = WaterExplainDialog(act, R.style.dialog)
            dialog.show()
        }
        //系统简介
        tv_os.onClick {
            SystemExplainDialog(act, R.style.dialog).show()
        }
        //科普知识
        tv_about.onClick {
            QADialog(act, R.style.dialog).show()
        }
        //注销
        tv_cancellation.onClick {
            SharedPreferencesFactory.cleardata(act, "username")
            SharedPreferencesFactory.cleardata(act, "password")
            startActivity<LoginActivity>()
            act.finish()
        }
    }


    override fun onDestroy() {
        super.onDestroy()
        showdialogchcek(act, "loaddismiss")
    }

}